package com.app.base.adapter;


import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import com.app.view.FilterImageView;
import com.caszx.chargingpile.R;
import com.squareup.picasso.Picasso;

public class RecyclerviewHorizontalAdapter extends RecyclerView.Adapter<RecyclerviewHorizontalAdapter.ViewHolder> implements OnClickListener
{
	
	private Context mContext;
	private String[] imgas ;


	public interface OnRecyclerViewItemClickListener {
		void onItemClick(View view, int position);
	}
	protected OnRecyclerViewItemClickListener mOnItemClickListener = null;
	public void setOnItemClickListener(OnRecyclerViewItemClickListener listener) {
		this.mOnItemClickListener = listener;
	}
	
	
	public RecyclerviewHorizontalAdapter(Context context){
		mContext = context;
	}
	
	
	public void setDatas(String[] imgas ){

		this.imgas = imgas;
		notifyDataSetChanged();
	}
	
	@Override
	public int getItemCount() {
		if(imgas== null) return 0;
		return imgas.length;
	}


	@Override
	public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int arg1) {
		View view = View.inflate(viewGroup.getContext(),
		R.layout.item_horizontal_image, null);
		ViewHolder holder = new ViewHolder(view);
		return holder;
	}
	@Override
	public void onBindViewHolder(final ViewHolder viewHolder, final int position) {
		Picasso.with(mContext)
				.load(imgas[position])
				.placeholder(R.drawable.bitmap_error_picasso)
				.config(Bitmap.Config.RGB_565)
				.error(R.drawable.bitmap_error_picasso)
				.into(viewHolder.filter_img);
		viewHolder.filter_img.setTag(position);
		viewHolder.filter_img.setOnClickListener(this);
	}


	@Override
	public void onClick(View v) {
		if (mOnItemClickListener != null) {
			int position = (int) v.getTag();
			mOnItemClickListener.onItemClick(v,position);
		}
	}
	 static class ViewHolder extends RecyclerView.ViewHolder {
		public FilterImageView filter_img;
		public ViewHolder(View itemView) {
			super(itemView);
			filter_img = (FilterImageView) itemView.findViewById(R.id._img);
		}
	}
}
